#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 40;
int n;
int map_[N][N];
bool color[N][N];
typedef pair<int,int> pii;
pii que[N*N];
int dx[4]={1,0,-1,0};
int dy[4]={0,-1,0,1};
void bfs(int x,int y)
{
	memset(color,1,sizeof(color));
	int hh=0,tt=0;
	que[hh]={x,y};
	while(hh<=tt)
	{
		auto now = que[hh++];
		
		for(int i=0;i<4;i++)
		{
			int xx=now.first+dx[i],yy=now.second+dy[i];
			if(xx<0||yy<0||xx>n+1||yy>n+1)continue;
			if(map_[xx][yy]!=0)continue;
			if(!color[xx][yy])continue;
			color[xx][yy]=false;
			que[++tt]={xx,yy};
		}
	}
}
int main()
{
	
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			scanf("%d",&map_[i][j]);
		}
	}
	bfs(0,0);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(color[i][j]&&map_[i][j]==0)
			{
				map_[i][j]=2;
			}
			printf("%d ",map_[i][j]);
		}
		printf("\n");
	}
	return 0;
}
